<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div >
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
		<el-select v-model="query.businessId" clearable placeholder="商户列表" class="filter-item" style="width: 130px">
		  <el-option v-for="item in businessNameList"
		    :value="item.id"
		    :key="item.id"
		    :label="item.businessName">
		  </el-option>
		</el-select>
        <rrOperation :crud="crud" />
		<!-- 导出 -->
		<el-button
		  :loading="crud.downloadLoading"
		  :disabled="!crud.data.length"
		  class="filter-item"
		  size="mini"
		  type="warning"
		  icon="el-icon-download"
		  @click="crud.doExport"
		>导出</el-button>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <!-- <crudOperation :permission="permission" /> -->
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="寄存订单ID">
            <el-input v-model="form.id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="门店id(第一期默认）">
            <el-input v-model="form.storeId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回收订单号" prop="orderNo">
            <el-input v-model="form.orderNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户id" prop="uid">
            <el-input v-model="form.uid" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="用户账号" prop="userName">
            <el-input v-model="form.userName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="检测师id" prop="userTesterId">
            <el-input v-model="form.userTesterId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回收商品" prop="depositGoods">
            <el-input v-model="form.depositGoods" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回收商品图片(最大5张)" prop="goodsImg">
            <el-input v-model="form.goodsImg" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回收金额" prop="depositAmount">
            <el-input v-model="form.depositAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回收商品描述">
            <el-input v-model="form.introduction" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回收凭证：(支付截图凭证)">
            <el-input v-model="form.depositVoucher" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="交付类型（0邮寄；1当面）" prop="deliverType">
            <el-input v-model="form.deliverType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="快递单号">
            <el-input v-model="form.expressNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="快递类型">
            <el-input v-model="form.expressType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="回收备注">
            <el-input v-model="form.recoverRemarks" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否删除" prop="isDel">
            <el-input v-model="form.isDel" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建时间" prop="createTime">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="updateTime">
            <el-input v-model="form.updateTime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table :summary-method="getSummaries" show-summary ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" v-if="false"/>
        <el-table-column show-overflow-tooltip v-if="columns.visible('orderNo')" prop="orderNo" label="回收订单号" />
		<el-table-column show-overflow-tooltip v-if="columns.visible('userName')" prop="businessName" label="所属招商" width="100"/>
        <el-table-column show-overflow-tooltip v-if="columns.visible('userName')" prop="userName" label="用户账号" width="100"/>
        <el-table-column show-overflow-tooltip v-if="columns.visible('depositGoods')" prop="depositGoods" label="回收商品" />
        <el-table-column sortable show-overflow-tooltip v-if="columns.visible('depositAmount')" prop="depositAmount" label="回收金额" />
        <el-table-column show-overflow-tooltip prop="deliverType" label="交付类型" width="80">
            <template slot-scope="scope">
                <div v-if="scope.row.deliverType === 0">
                  <b  style="display: inline-block">0-邮寄</b>
                </div>
              <span v-else style="color: red;" slot="reference">1-当面</span>       
            </template>
          </el-table-column>
        <el-table-column show-overflow-tooltip v-if="columns.visible('recoverRemarks')" prop="recoverRemarks" label="回收备注" />
        <el-table-column show-overflow-tooltip v-if="columns.visible('createTime')" prop="createTime" label="创建时间" width="140">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip v-if="columns.visible('signerOrderName')" prop="signerOrderName" label="签单人" width="140"/>
        <!-- <el-table-column v-permission="['admin','syOrderRecoverInfo:edit','syOrderRecoverInfo:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudSyOrderRecoverInfo from '@/api/syOrderRecoverInfo'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from "@/components/material";
import { getBusinessNameList } from '@/api/syBusinessName'

// crud交由presenter持有
const defaultCrud = CRUD({ title: 'SyOrderRecoverInfoController', url: 'api/syOrderRecoverInfo', sort: 'create_time,desc', crudMethod: { ...crudSyOrderRecoverInfo }})
const defaultForm = { id: null, storeId: null, orderNo: null, uid: null, userName: null, userTesterId: null, depositGoods: null, goodsImg: null, depositAmount: null, introduction: null, depositVoucher: null, deliverType: null, expressNumber: null, expressType: null, recoverRemarks: null, isDel: null, createTime: null, updateTime: null }
export default {
  name: 'SyOrderRecoverInfo',
  components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
      rules: {
        orderNo: [
          { required: true, message: '回收订单号不能为空', trigger: 'blur' }
        ],
        uid: [
          { required: true, message: '用户id不能为空', trigger: 'blur' }
        ],
        userName: [
          { required: true, message: '用户账号不能为空', trigger: 'blur' }
        ],
        userTesterId: [
          { required: true, message: '检测师id不能为空', trigger: 'blur' }
        ],
        depositGoods: [
          { required: true, message: '回收商品不能为空', trigger: 'blur' }
        ],
        goodsImg: [
          { required: true, message: '回收商品图片(最大5张)不能为空', trigger: 'blur' }
        ],
        depositAmount: [
          { required: true, message: '回收金额不能为空', trigger: 'blur' }
        ],
        deliverType: [
          { required: true, message: '交付类型（0邮寄；1当面）不能为空', trigger: 'blur' }
        ],
        isDel: [
          { required: true, message: '是否删除不能为空', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'storeId', display_name: '门店id(第一期默认）' },
        { key: 'orderNo', display_name: '回收订单号' },
        { key: 'uid', display_name: '用户id' },
        { key: 'userName', display_name: '用户账号' },
        { key: 'userTesterId', display_name: '检测师id' },
        { key: 'depositGoods', display_name: '回收商品' }
      ],
	  businessNameList: [],//商户列表
    }
  },
  watch: {
  },
  created() {
    let that = this;
    setTimeout(function() {
      that.getBusinessListInit();
    }, 500);
  },
  methods: {
    getSummaries (param) {
        const { columns, data } = param
        const sums = []
        columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '总计'
        } else if (index === 5) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return (parseFloat(prev) + parseFloat(curr)).toFixed(2);
            } else {
              return parseFloat(prev).toFixed(2);
            }
          }, 0)
        } else {
          sums[index] = 'N/A'
        }
      } else {
        sums[index] = ''
      }
    })
      return sums
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }else{
        delete this.crud.params.storeId
        delete this.crud.params.orderNo
        delete this.crud.params.uid
        delete this.crud.params.userName
        delete this.crud.params.userTesterId
        delete this.crud.params.businessId
        delete this.crud.params.depositGoods
      }
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
	getBusinessListInit(){
	  getBusinessNameList().then(res => {
	    this.businessNameList = res;
	  })
	},
  }
}



</script>

<style scoped>

  ::v-deep .el-table__footer-wrapper tbody td {
    color: red;
    font-weight: bold;
  }
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
